/*
 * Copyright (c) 2018-2024 北京华恒盛世科技有限公司
 * QUICKPOOL is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *     http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
*/

#ifndef TREE_H
#define TREE_H

#include "hash.h"

/* tree entry structure */
struct tree {
    char *name;
    struct treeNode *root;
    HASH_TABLE_T *node_table;
    LIST_T *leaf_list;
};

/* tree node structure */
struct treeNode {
    struct treeNode *parent;
    struct treeNode *child;
    struct treeNode *left;
    struct treeNode *right;
    char *name;
    void *data;
};

extern struct tree *tree_create(const char *);
extern void tree_destroy(struct tree *);
extern struct treeNode *tree_insert_node(struct treeNode *, struct treeNode *);
extern struct treeNode *tree_remove_node(struct treeNode *);
extern int tree_traverse(struct tree *, int (*)(struct treeNode *, struct tree *));
extern struct treeNode *tree_next_node(struct treeNode *);
extern struct treeNode *tree_remove_leaf(struct treeNode *);

#endif
